package com.changgou.goods.dao;

import com.changgou.goods.pojo.Brand;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface BrandMapper extends Mapper<Brand> {

    /**
     * 根据分类名称查询品牌列表
     * @param categoryName
     * @return
     */
    @Select("SELECT b.NAME,\n" +
            "\tb.image \n" +
            "FROM\n" +
            "\ttb_category c,\n" +
            "\ttb_category_brand cb,\n" +
            "\ttb_brand b \n" +
            "WHERE\n" +
            "\tb.id = cb.brand_id \n" +
            "\tAND c.id = cb.category_id \n" +
            "\tAND c.NAME = #{name}")
    List<Map> findListByCategoryName(@Param("name") String categoryName);

    /**
     * 根据分类名称查询规格列表
     * @param categoryName
     * @return
     */
    @Select("SELECT s.name,s.options FROM tb_spec s WHERE s.template_id IN (SELECT c.template_id FROM tb_category c where c.name = #{name})")
    List<Map> findSpecListByCategoryName(@Param("name") String categoryName);
}
